<template>
  <div>
    <!-- 关联商品 {搜索功能需调整接口参数需调整}-->
    <div class="abouttalent" id="abouttalent" v-if="hasRoot">
      <div class="title">达人列表</div>
      <div class="ld_search_date">
        <radio_group :radio_values="['近7天', '15天', '30天']" v-model="KindName" class="tab01" />
        <!-- 筛选 -->
        <div class="filtr_btn" @click="activeFiltr = !activeFiltr">
          <i></i>
          <span>筛选</span>
        </div>
      </div>
      <van-popup
        v-model="activeFiltr"
        position="right"
        :class="'filtr_select_box'"
        :get-container="'body'"
      >
        <div class="f_content">
          <van-collapse v-model="filtrActive">
            <van-collapse-item title="达人行业" :name="1">
              <div class="f_btn_box">
                <i
                  v-for="(item, idx) in categoryList1"
                  :class="{ active: item.active }"
                  @click="categoryDataFn(item)"
                  :key="idx"
                >{{ item.name }}</i>
                <i class="mores" @click="unfoldMoreFn" v-if="categoryList.length > 12">{{
                isUnfold ? "收起" : "展开更多"
                }}</i>
              </div>
            </van-collapse-item>
            <van-collapse-item title="粉丝数量" :name="2">
              <div class="f_btn_box">
                <i
                  v-for="(item, idx) in numberList"
                  :class="{ active: item.active }"
                  @click="fNumberDataFn(item)"
                  :key="idx"
                >{{ item.name }}</i>
              </div>
            </van-collapse-item>
          </van-collapse>
        </div>
        <div class="f_btns_sub">
          <i @click="resetFiltr">重置</i>
          <i class="active" @click="subFiltr">确定</i>
        </div>
      </van-popup>
      <!-- 搜索框 -->
      <div class="searchBox">
        <input
          type="text"
          v-model.trim="keyword"
          placeholder="请输入达人名称关键词搜索"
          @keyup.enter="toSearch"
        />
        <img src="@/assets/one/seach.png" v-if="!imgBox" @click="toSearch" />
        <img src="@/assets/two/search.png" v-if="imgBox" @click="toSearch" />
      </div>
      <!-- 达人列表 -->
      <!-- <div class="title title2">达人列表</div> -->
      <div v-if="talentList && talentList.length">
        <div
          class="goodsbox"
          v-for="(item, index) in talentList"
          :key="index"
          @click="todatails(item.authorId)"
        >
          <div class="img_tit">
            <img :src="item.logo" class="img" />
            <div>
              <h3>
                {{ item.nickName }}
              </h3>
              <p>
                <span>粉丝数：{{ format_num(item.totalFans) }}</span>
              </p>
            </div>
          </div>
          <div class="databox">
            <div>
              <span>{{ item.publicPraise }}</span>口碑分
            </div>
            <div>
              <span>{{ format_num(item.relAwemeCount) }}</span>关联直播
            </div>
            <div>
              <span>{{ format_num(item.relLiveCount) }}</span>关联视频
            </div>
          </div>
        </div>
      </div>
      <div v-if="loading" style="margin-top: 1rem;">
        <van-loading class="loading" v-if="loading" type="spinner" :vertical="true" />
      </div>
      <!-- 查看更多 -->
      <div class="more" @click="addMore" v-if="!isOver && talentList.length != 0 && !loading">查看更多</div>
      <p
        class="bott"
        v-if="isOver && !loading && talentList.length != 0"
      >我是有底线的~</p>
      <!-- 暂无数据 -->
      <div class="zanwu" v-if="talentList.length == 0 && !loading">
        <img src="@/assets/one/zw.png" />
        <p>暂无数据</p>
      </div>
    </div>
    <noPower :minLeve="$store.state.userRoot[88][91].ownerMinLevel" v-else />
  </div>
</template>
<script>
import BigPie from '@/component/BigPiebrand.vue';
import radio_group from './component/radio_group.vue';
export default {
  components: { BigPie, radio_group },
  data() {
    return {
      active: 0,
      keyword: '',
      KindName: '30天',
      searchDates: [], //存放开始时间和结束时间
      count: 0, // 直播列表长度
      page: 1,
      isOver: false,
      imgBox: false,
      talentList: [], //商品列表
      loading1: false, //图表的loading
      loading: false, // 列表中的
      count: '', // 商品列表长度
      isOver: false,
      page: 1, //默认页数
      activeFiltr: false, //是否展开筛选下拉框
      filtrActive: [1], //默认打开哪个筛选条件
      categoryList: [], // 商品来源总数据
      categoryList1: [], // 商品来源
      categoryList2:[],
      categoryId: -1, //来源id
      numSection: '全部', //数量区间
      hasRoot: true,
      isUnfold: false, //是否展开更多
      numberList:[
        {active:true,name:'全部',value:'全部'},
        {active:false,name:'<1w',value:'0-10000'},
        {active:false,name:'1w-10w',value:'10000-100000'},
        {active:false,name:'10w-50w',value:'100000-500000'},
        {active:false,name:'50w-100w',value:'500000-1000000'},
        {active:false,name:'100w-500w',value:'1000000-5000000'},
        {active:false,name:'500w-1000w',value:'5000000-10000000'},
        {active:false,name:'>1000w',value:'10000000-1000000000'},
      ]
    };
  },
  watch: {
    // 搜索
    keyword: function (newVal, oldVal) {
      if (newVal == '') {
        this.imgBox = false;
        this.talentList = [];
        this.page = 1;
        this.isOver = false;
        this.getListData();
      } else {
        this.keyword = newVal;
        this.imgBox = true;
      }
    },
    KindName: function (newVal, oldVal) {
      if (this.KindName != '') {
        this.KindName = newVal;
        this.page = 1;
        this.talentList = [];
        this.getTime();
        this.getListData();
      }
    }
  },
  created() {
    this.getTime(); //时间
    this.getClassifyData(); // 类目+来源+价格区间
    this.getListData(); // 商品列表
  },
  methods: {
    //   搜索
    toSearch() {
      this.talentList = [];
      this.page = 1;
      this.loading = true;
      this.getListData();
    },

    // 获取时间
    getTime() {
      switch (this.KindName) {
        case '近7天':
          this.endDate = this.timestamp(Date.now() / 1000 - 1 * 86400, 'Y-M-D');
          this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 7, 'Y-M-D');
          break;
        case '15天':
          this.endDate = this.timestamp(Date.now() / 1000 - 1 * 86400, 'Y-M-D');
          this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 15, 'Y-M-D');
          break;
        case '30天':
          this.endDate = this.timestamp(Date.now() / 1000 - 1 * 86400, 'Y-M-D');
          this.startDate = this.timestamp(Date.now() / 1000 - 86400 * 30, 'Y-M-D');
          break;
        default:
          this.startDate = this.liveTime[0];
          this.endDate = this.liveTime[1];
          break;
      }
      this.liveTime = [this.startDate, this.endDate];
    },
    // 获取 商品来源，商品类目，价格区间
    getClassifyData() {
      this.$axios
        .get('/api/Brand/GetFansCategoryAnalyse', {
          params: {
            brandId: this.$route.query.id,
            startDate: this.startDate,
            endDate: this.endDate
          }
        })
        .then(res => {
          if (res.data.code == 0) {
            res.data.data.category.forEach((item, idx) => {
              item.active = !Boolean(idx);
            });
            this.categoryList = res.data.data.category;
            this.categoryList1 = res.data.data.category.slice(0, 11); // 来源
            this.categoryList2 = res.data.data.category.slice(11, res.data.data.category.length); // 来源
          }
        });
    },
    unfoldMoreFn() {
      this.isUnfold = !this.isUnfold;
      if (this.isUnfold) {
        this.categoryList1 = this.categoryList1.concat(this.categoryList2);
      } else {
        this.categoryList1 = this.categoryList1.slice(0, 11);
      }
    },
    // get达人列表
    getListData() {
      this.loading = true;
      // let pms = {
      //   Fans: "全部",
      //   brandId: this.$route.query.id,
      //   startDate: this.startDate,
      //   endDate: this.endDate,
      //   keyword: this.keyword,
      //   order_by: "desc",
      //   page: this.page,
      //   price: this.numSection,
      //   categoryId: this.categoryId,
      //   size: 10,
      //   sort: 4,
      // }
      let pms = {
        "brandId":this.$route.query.id,
        "startDate":this.startDate,
        "endDate":this.endDate,
        "CategoryId":this.categoryId,
        "Fans":this.numSection,
        "page":this.page,
        "size":30,
        "order_by":0,
        "sort":1,
        "keyword":this.keyword
      }
      // let pms = {
      //   brandId: this.$route.query.id,
      //   startDate: this.startDate,
      //   endDate: this.endDate,
      //   categoryId: this.categoryId, // 商品来源
      //   key: this.keyword,
      //   price: this.numSection,
      //   order_by: 'desc', // 排序方式（倒序）
      //   page: this.page,
      //   size: 10,
      //   sort: 4 //排序规则
      // };
      this.$axios.post('/api/Brand/BrandRelAuthor', pms).then(res => {
        this.loading = false;
        if (res.data.code == 0) {
          if (res.data.data.length != 0) {
            this.talentList = this.talentList.concat(res.data.data);
            this.count = res.data.count;
          }
          if (this.talentList.length >= this.count) {
            this.isOver = true;
          }
        }else if(res.data.code == 1002){

        }else if(res.data.code == 1003){
          this.hasRoot = false;
        }
        
      });
    },
    //筛选框重置按钮
    resetFiltr() {
      this.categoryId = -1;
      this.numSection = '全部';
      this.categoryList1.forEach((item, idx) => {
        item.active = !idx;
      });
      this.numberList.forEach((item, idx) => {
        item.active = !idx;
      });
    },
    //筛选框确定按钮
    subFiltr() {
      this.page = 1;
      this.talentList = [];
      this.activeFiltr = false;
      this.getListData();
    },
    //筛选-商品来源
    categoryDataFn(item) {
      this.categoryList1.forEach(itemC => {
        itemC.active = item == itemC;
      });
      this.categoryId = item.value;
    },
    //筛选-价格区间
    fNumberDataFn(item) {
      this.numberList.forEach(itemC => {
        itemC.active = item == itemC;
      });
      this.numSection = item.value;
    },
    // 查看更多
    addMore() {
      this.page = this.page + 1;
      this.getListData();
    },
    //跳转商品详情
    todatails(id) {
      this.$router.push({ path: '/talentdetails', query: { id: id } });
    }
  }
};
</script>
<style lang="less" scoped>
* {
  margin: 0;
  padding: 0;
}
// tab日期切换
.ld_search_date {
  margin-top: 0.4rem;
  font-size: 0;
  display: flex;
  justify-content: space-between;
  .filtr_btn {
    font-size: 0;
    i {
      display: inline-block;
      width: 0.3333rem;
      height: 0.3333rem;
      background: url('../../assets/img/filter.png') no-repeat;
      background-size: 100% 100%;
      vertical-align: middle;
    }

    span {
      display: inline-block;
      margin-left: 0.186667rem;
      font-size: 0.373333rem;
      color: #555;
      vertical-align: middle;
    }

    &.active {
      i {
        background: url('../../assets/img/filter_ed.png');
      }
      span {
        color: #fd7f2c;
      }
    }
  }
}
.abouttalent {
  width: 9.2rem;
  margin: 0 auto;
  padding-bottom: 0.666667rem;
}
.title {
  position: relative;
  padding-left: 0.266667rem;
  font-size: 0.4rem;
  color: #222;
  margin-top: 0.6933rem;
  &:before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.1rem;
    display: inline-block;
    width: 0.08rem;
    height: 0.373333rem;
    background-color: #fd7f2c;
    border-radius: 3px;
  }
}
/* 搜索框 */
.searchBox {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  border-radius: 0.1333rem;
  border: solid 1px #e5e5e5;
  width: 9.2rem;
  height: 0.986667rem;
  padding-left: 0.5rem;
  margin-top: 0.2666rem;
  margin-bottom: 0.4rem;
  input[type='text'] {
    width: 86%;
    height: 100%;
    border: none;
    font-size: 0.3733rem;
    color: #222;
  }
  input {
    //处理ios兼容性(阴影)
    -webkit-appearance: none;
  }
  img {
    width: 0.4rem;
    height: 0.4rem;
    margin-left: 0.4rem;
  }
}
//  商品列表
.title2 {
  margin-top: 0 !important;
}
.goodsbox {
  padding-top: 0.3733rem;
  .img_tit {
    display: flex;
    .img {
      width: 1.333333rem;
      height: 1.333333rem;
      border-radius: 1.333333rem;
      margin-right: 0.24rem;
    }
    h3 {
      img {
        display: inline-block;
        width: 0.4rem;
        height: 0.4rem;
        margin-right: 0.12rem;
        margin-top: -0.05rem;
      }
      width: 7.62666rem;
      font-size: 0.4rem;
      color: #222;
      font-weight: 500;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      padding-top: 0.10666rem;
    }
    p {
      font-size: 0;
      margin-top: .1333rem;
      span {
        font-size: .32rem;
        // padding: .0667rem .1333rem;
        color: #555;
      }
    }
  }
  .databox {
    display: flex;
    justify-content: space-around;
    padding: 0.4rem 0;
    border-bottom: 1px solid #e5e5e5;
    div {
      span {
        display: block;
        font-family: DINPro-Medium;
        font-size: 0.4rem;
        color: #222;
      }
      font-size: 0.32rem;
      color: #888;
      text-align: center;
    }
  }
}

/* 筛选 */
.filtr_select_box {
  width: 80%;
  height: 100%;
  overflow: hidden;
  .f_content {
    position: relative;
    z-index: 10;
    height: calc(100% - 1.8rem);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    .f_btn_box {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      font-size: 0;
      &:after {
        content: '';
        width: 2.88rem;
        height: 0;
        margin-right: 0.266rem;
      }
      i {
        display: inline-block;
        box-sizing: border-box;
        width: 2.88rem;
        height: 0.85333rem;
        margin-bottom: 0.306667rem;
        margin-right: 0.266rem;
        line-height: 0.8533rem;
        border-radius: 0.1333rem;
        font-size: 0.3466rem;
        border: solid 1px #e5e5e5;
        text-align: center;
        font-style: normal;
        color: #555;

        // &:nth-child(3n) {
        //   margin-right: 0;
        // }

        &.active {
          background-color: #fff4ed;
          border-color: #fd7f2c;
          color: #fd7f2c;
        }

        &.mores {
          color: #fd7f2c;
        }
      }
    }
  }

  .f_btns_sub {
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 0.2666rem 0;
    text-align: center;
    font-size: 0;
    box-sizing: border-box;
    i {
      display: inline-block;
      width: 2.6666rem;
      height: 1.04rem;
      line-height: 1.04rem;
      font-size: 0.3733rem;
      text-align: center;
      border-radius: 0.1333rem;
      border: solid 1px #e5e5e5;
      background-color: #fff;
      font-style: normal;
      color: #888;

      &.active {
        background-color: #fd7f2c;
        border-color: #fd7f2c;
        color: #fff;
      }

      &:first-child {
        margin-right: 0.36rem;
      }
    }
  }
}

//   查看更多
.more {
  margin: 0.6667rem auto 0 auto;
  width: 2.1333rem;
  height: 0.8rem;
  line-height: 0.8rem;
  border-radius: 0.1333rem;
  border: solid 1px #fd7f2c;
  font-size: 0.3467rem;
  color: #fd7f2c;
  text-align: center;
}
.bott {
  font-size: 0.32rem;
  color: #b5b5b5;
  text-align: center;
  line-height: 1.0666rem;
}
//   暂无数据
.zanwu {
  width: 5.3333rem;
  height: 4rem;
  margin: 1rem auto 0 auto;
  img {
    margin: 0 auto;
    width: 4rem;
    height: 3.2rem;
    display: block;
  }
  p {
    font-size: 0.3467rem;
    line-height: 0.4rem;
    color: #888;
    text-align: center;
  }
}
</style>
